package com.example.download.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.download.bean.downloaded_item
import com.example.download.R
import com.example.download.bean.downloading_item

class downloaded_itemAdapter (private val downloadeditemList: MutableList<downloaded_item>): RecyclerView.Adapter<downloaded_itemAdapter.ViewHolder>(){
    class ViewHolder(view: android.view.View): RecyclerView.ViewHolder(view){
        val tv_dle_item_imageView: android.widget.ImageView = view.findViewById(R.id.tv_dle_item_imageView)
        val tv_dle_item_title: android.widget.TextView = view.findViewById(R.id.tv_dle_item_title)
        val tv_dle_item_date: android.widget.TextView = view.findViewById(R.id.tv_dle_item_date)
        val iv_dle_item_other: android.widget.ImageView = view.findViewById(R.id.iv_dle_item_other)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.downloaded_item,parent,false)
        return ViewHolder(view)
    }
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = downloadeditemList[position]
        holder.tv_dle_item_imageView.setImageResource(item.tv_dle_item_imageView?.toInt()?:0)
        holder.tv_dle_item_title.text = item.tv_dle_item_title
        holder.tv_dle_item_date.text = item.tv_dle_item_date
        holder.iv_dle_item_other.setImageResource(item.iv_dle_item_other?.toInt()?:0)
    }
    override fun getItemCount(): Int {
        return downloadeditemList.size
    }
    fun updateData(newList: List<downloaded_item>) {
        downloadeditemList.clear()
        downloadeditemList.addAll(newList)
        notifyDataSetChanged()
    }
}